package logic

import (
	"context"
	"errors"
	"user/models/mysql"

	"user/userrpc/internal/svc"
	"user/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodShowLogic {
	return &GoodShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品详情
func (l *GoodShowLogic) GoodShow(in *userrpc.GoodShowRequest) (*userrpc.GoodShowResponse, error) {
	// todo: add your logic here and delete this line
	var good mysql.Good
	err := good.FindUserByUserId(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("详情查询失败")
	}
	return &userrpc.GoodShowResponse{
		UserId:    good.UserId,
		GoodName:  good.GoodName,
		GoodPrice: float32(good.GoodPrice),
		GoodImage: good.GoodImage,
		GoodStock: good.GoodStock,
	}, nil
}
